home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 76 / XENIATGM66.iso / Indiana Jones / Indiana Jones.exe / RESOURCE / PREVIEW.GOB / cog_sea_doorrotate_l.cog < prev    next >
Text File  |  1999-11-15  |  8KB  |  309 lines

  1. # Jones 3D Cog Script
  2. #
  3. # sea_DoorRotate_L.cog
  4. #
  5. # Rotating Door Script
  6. #
  7. # [DS & modified by HB]
  8. # [Further bulletproofing by PKM]
  9. #
  10. # (C) 1999 LucasArts Entertainment Co. All Rights Reserved
  11. # ==============================================================================
  12.  
  13. symbols
  14.  
  15.     message        startup
  16.     message        activate    
  17.     message        arrived        
  18.     message        touched        
  19.     message        timer
  20.     message        user5 # prevent door closing
  21.     message        user6 # allow door closing
  22.  
  23.     sound        lockedtalk0=inxj076.wav                    local # This Door is locked.
  24.     sound        lockedtalk1=inxj077.wav                    local # it's locked.
  25.     sound        lockedtalk2=inxj078.wav                    local # locked.
  26.     sound        lockedtalk3=inxj088.wav                    local # Nope.
  27.  
  28.     sound        opensnd=sea_doors_open_c.wav            local
  29.     sound        closesnd=sea_doors_close_c.wav            local
  30.  
  31.       thing        door0
  32.     thing        switch0
  33.     thing        switch1
  34.     thing        player                            local
  35.     vector        v_dpos                                    local # door position
  36.     vector        v_ipos                                    local # indy position
  37.     vector        v_idvec                                    local # indy-to-door vec
  38.     vector        v_drvec                                    local # door right vec
  39.     vector        v_currentDoorPYR                        local
  40.     vector        v_openedDoorPYR                            local # door aim
  41.     vector        v_closedDoorPYR                            local # door aim
  42.     vector        v_openedDoorPosition                    local
  43.     vector        v_closedDoorPosition                    local
  44.     sector        openedDoorSector                        local
  45.     sector        closedDoorSector                        local
  46.  
  47.     flex        OpenDoors                                local # label
  48.     flex        CloseDoors                                local # label
  49.  
  50.     flex        f_iposcheck                                local # dot result indy relative to door
  51.     flex        touchangle                                local
  52.     flex        closeangle                                local
  53.     flex        reopenangle                                local
  54.     flex        timeratio                                local
  55.     flex        reopentime                                local
  56.     flex        doortime=1.0
  57.     flex        opentime=4.0                            local # adjustable
  58.  
  59.     int            locked=0                                # switch0 locked=1, unlocked=0
  60.     int            firstTime=1                                local # 1 = first time door is opened
  61.     int            open=0                                    local
  62.     int            newline                                    local
  63.     int            notnow=0                                local
  64.     int            alreadytouched=0                        local
  65.     int            oldline=50                                local
  66.     int            stopclose=0                                local # default to allow closing!
  67.  
  68.     vector        v_ButLook local   
  69.     vector        v_IndyLook local   
  70.     flex        f_dot    local
  71.  
  72.     # NOTE:  door0 has 4 states...
  73.     # closed    --> open == 0 (init state)
  74.     # opening    --> open == 1
  75.     # open        --> open == 2
  76.     # closing    --> open == 3
  77.  
  78. end
  79.  
  80. # ==============================================================================
  81.  
  82. code
  83.  
  84. # ..............................................................................
  85.  
  86. startup:
  87.  
  88.     player = GetLocalPlayerThing();
  89.     v_closedDoorPYR = GetThingLVecPYR(door0);
  90.     v_closedDoorPosition = GetThingPos(door0);
  91.     closedDoorSector = GetThingSector(door0);
  92.     return;
  93.  
  94. # ..............................................................................
  95.  
  96. user5:
  97.  
  98.     # NOTE: as of 7/29/99 only known sender is sea_leverpump.cog
  99.     # and only known recipients are cogs tied to the leverpump doors [HB]
  100.  
  101.     # Don't allow door to close...
  102.     stopclose = 1;
  103.     return;
  104.  
  105. # ..............................................................................
  106.  
  107. user6:
  108.  
  109.     # NOTE: as of 7/29/99 only known sender is sea_leverpump.cog
  110.     # and only known recipients are cogs tied to the leverpump doors [HB]
  111.     
  112.     # Okay to close door...
  113.     stopclose = 0;
  114.     return;
  115.  
  116. # ..............................................................................
  117.  
  118. activate:
  119.     if (GetSenderRef() == door0)
  120.     {
  121.         return;
  122.     }
  123.     // Make sure Indy facing button so that he can't activate from other side of thin wall
  124. //    DebugPrint("L Door Activated");
  125.     v_ButLook = GetThingLVec(GetSenderRef());
  126.     v_IndyLook = GetThingLVec(player);
  127.     f_dot = VectorDot(v_ButLook, v_IndyLook);
  128. //    DebugFlex(f_dot, "dot");
  129.     if (f_dot < 0.0)
  130.     {
  131.         return;
  132.     }
  133.  
  134.     if (notnow == 1)
  135.     {
  136.         return;
  137.     }
  138.     notnow = 1;
  139.     SetActorFlags(player, 0x200000); # no control
  140.     StopThing(player);
  141.     DeselectWeaponWait(player);
  142.     PlayMode(player, 60, 0);
  143.  
  144.     # ----------- Locked One Way Door -----------
  145.     if ((locked == 1) && (GetsenderRef() == switch0))
  146.     {        
  147.         while (newline == oldline)
  148.         {        
  149.             newline = RandBetween(0, 3);
  150.         }
  151.         oldline = newline;
  152.         PlayVoice(player, lockedtalk0[newline], 1.0, 1);
  153.  
  154.         notnow = 0;
  155.         ClearActorFlags(player, 0x200000);
  156.  
  157.         return;
  158.     }
  159.  
  160.     # ----------- Locked One Way Door ------------
  161.     locked = 0;
  162.     Sleep(0.2);
  163.     MoveToFrame(switch0, 1, 1);
  164.     MoveToFrame(switch1, 1, 1);
  165.     Sleep(0.5);
  166.     ClearActorFlags(player, 0x200000);
  167.     Call OpenDoors;
  168.  
  169.     return;
  170.  
  171. # ..............................................................................
  172.  
  173. arrived:
  174.     if (GetSenderRef() == door0 && open == 1)
  175.     {
  176.         if (firstTime == 1)
  177.         {
  178.             // First time opening door - remember doors position & orientation for later.
  179.             v_openedDoorPYR = GetThingLVecPYR(door0);
  180.             v_openedDoorPosition = GetThingPos(door0);
  181.             openedDoorSector = GetThingSector(door0);
  182.         }
  183.         else
  184.         {
  185.             // Slam it open.
  186.             SetThingLVecPYR(door0, v_openedDoorPYR);
  187.             SetThingPosEx(door0, v_openedDoorPosition, openedDoorSector);
  188.         }
  189.  
  190.         open = 2; # door is now open
  191.         SetTimer(opentime); # per HB...was sleeptime
  192.     }
  193.  
  194.     if (GetSenderRef() == door0 && open == 3)
  195.     {        
  196.         if (alreadytouched == 1)
  197.         {
  198.             return;
  199.         }
  200.  
  201.         movetoframe(switch0, 0, 1);
  202.         movetoframe(switch1, 0, 1);
  203.  
  204.         // Slam it closed.
  205.         SetThingLVecPYR(door0, v_closedDoorPYR);
  206.         SetThingPosEx(door0, v_closedDoorPosition, closedDoorSector);
  207.  
  208.         open = 0; # door is now closed
  209.         notnow = 0;
  210.     }
  211.  
  212.     return;
  213.  
  214. # ..............................................................................
  215.  
  216. touched:
  217.     if (GetSenderRef() == door0 && open == 3 && alreadytouched == 0)
  218.     {
  219.         alreadytouched = 1; # suppress multiple hits
  220.  
  221.         # check if Indy is touching back side of door...
  222.         v_dpos = GetThingPos(door0); # door hinge
  223.         v_ipos = GetThingPos(player); # our hero
  224.          v_idvec = VectorNorm(VectorSub(v_dpos, v_ipos)); # direction between indy & door 
  225.         v_drvec = GetThingLVec(door0); # check 90 to door plane
  226.         f_iposcheck = VectorDot(v_idvec, v_drvec); # places indy in- or outside door
  227.  
  228.         if (f_iposcheck > 0)
  229.         {
  230.             # Don't re-open if Indy is touching back side...
  231.             alreadytouched = 0;
  232.             return;
  233.         }
  234.             
  235.         open = -1;
  236.         StopThing(door0); # but first we stop it
  237.         Sleep(0.1); # let engine update
  238.         open = 1; # door is going to open again
  239.  
  240.         # Get door angle at moment it's touched...
  241.         v_currentDoorPYR = GetThingLVecPYR(door0);
  242.         closeangle = VectorY(v_closedDoorPYR);
  243.         touchangle = VectorY(v_currentDoorPYR);
  244.  
  245.         # Get rotation angle door needs to fully re-open...    
  246.         # PRO TIP:  the engine uses angles *backwards* from the Rotate() verb    
  247.         reopenangle = ((closeangle - 90) - touchangle); # for L-doors 
  248.         if (reopenangle < -360)
  249.         {
  250.             reopenangle = (reopenangle + 360);
  251.         }
  252.             
  253.         # How far open...?
  254.         timeratio = (Abs(reopenangle) / 90); # what percentage?
  255.         reopentime = (doortime * timeratio); # calculate time
  256.         Rotate(door0, -reopenangle, 1, reopentime); # re-open 
  257.     }
  258.  
  259.     return;
  260.  
  261. # ..............................................................................
  262.  
  263. timer:
  264.  
  265.     if (stopclose != 0)
  266.     {
  267.         # Don't close door, but start the timer again...
  268.         SetTimer(2.0); # this amounts to a pulse
  269.         return;
  270.     }
  271.  
  272.     Call CloseDoors;
  273.  
  274.     return;
  275.  
  276. # ..............................................................................
  277.  
  278. OpenDoors:
  279.  
  280.     if (open == 0)
  281.     {
  282.         Rotate(door0, 90, 1, doortime);
  283.         PlaySoundThing(opensnd, door0, 1, 5, 10, 0);
  284.         open = 1;
  285.         alreadytouched = 0; # init every time door opens
  286.     }
  287.  
  288.     return;
  289.  
  290. # ..............................................................................
  291.  
  292. CloseDoors:
  293.  
  294.     If (open == 2)
  295.     {
  296.         Rotate(door0, -90, 1, doortime);
  297.         PlaySoundThing(closesnd, door0, 1, 5, 10, 0);
  298.         open = 3;
  299.         alreadytouched = 0; # Indy can stop it again
  300.     }
  301.  
  302.     return;
  303.  
  304. # ..............................................................................
  305.  
  306.  
  307. end
  308.  
  309.